package com.ctgu.tengyun.bean.convert;

import com.ctgu.tengyun.bean.FileBean;
import com.ctgu.tengyun.util.StringUtils;

/**
 * Created by liaoweizhi on 2019/7/23.
 */
public class FileConvert {

    private static String filePathPrefix;

    public static FileBean fillFileBeanUrlPath(FileBean fileBean) {
        if (null != fileBean && StringUtils.isNotEmpty(fileBean.getUrl())) {
            fileBean.setUrl(filePathPrefix + fileBean.getUrl());
        }

        return fileBean;
    }

    public static void splitFileBeanUrlPath(FileBean fileBean) {
        if (null != fileBean && StringUtils.isNotEmpty(fileBean.getUrl())) {
            String fullUrlPath = fileBean.getUrl();
            if (fullUrlPath.contains(filePathPrefix)) {
                String[] split = fullUrlPath.split(filePathPrefix);
                fileBean.setUrl(split[split.length - 1]);
            }
        }
    }

    public static String getFilePathPrefix() {
        return filePathPrefix;
    }

    public static void setFilePathPrefix(String filePathPrefix) {
        FileConvert.filePathPrefix = filePathPrefix;
    }
}
